import {
	defineStore
} from 'pinia';
import {
	api
} from '../script/api.js'

export const store = defineStore('ipinfo', {
	state: () => {
		return {
			ipinfo: {},
			weather: {},
		}
	},
	actions: {
		updateIpInfo(cb) {
			const instance = this
			api.get('/tools/ipinfo', {
				ip: ''
			}, (data) => {
				if (data.success) {
					instance.ipinfo = data.data
					api.get('/tools/weather/live', {
						city: data.data.citycode
					}, (data) => {
						if (data.success) {
							instance.weather = data.data
						}
					})
				}
				// console.log()('ip信息', instance.ipinfo)
				if (cb) {
					cb(data.success)
				}
			})
		},
	},
})

export default store